import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '所属组织',		name: 'comp_id',	type:'select', loading:true, idStr:'uuid', nameStr:'company_name' },
			{ label: '物料编码',		name: 'mate_name' },
			{ label: '物料名称',		name: 'mate_type'},
			{ label: '物料分类',		name: 'category' },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		this.fetch()
	}
	
	// 获取下拉数据
	getSelect = async () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 所属组织
			$fn.setRow(forms, 'comp_id',  await f.getCache({ api:'company'}))
			this.setState({ forms })
		})
		
	}
	// 获取弹框下拉
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, [ 'unit' ], ()=>{
			$cache.then( async f => {
				// 单位
				$fn.setRow(formData, 'unit', await f.getDisCache({ code:22000 } ) )
				
				this.setState({ formData })
			})
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'material-template/index')
	
	// 表单
	cols = [
		{ title: '所属组织', 	dataIndex: 'company_name', 		width:150 },
		{ title: '物料编码', 	dataIndex: 'mate_number', 		width:150 },
		{ title: '物料名称', 	dataIndex: 'mate_name', 		width:150 },
		{ title: '物料分类', 	dataIndex: 'category', 			width:150 },
		{ title: '规格', 		dataIndex: 'mate_format', 		width:150 },
		{ title: '型号', 		dataIndex: 'version', 			width:150 },
		{ title: '生产商', 		dataIndex: 'mate_factory_name', width:150 },
		{ title: '主计量单位', 	dataIndex: 'unit_name', 		width:150},
		{ title: '方法学', 		dataIndex: 'methodology', 		width:150 },
	]
	// 操作按钮
	controls = () => [
		Controls.exports.call(this, 'material-template/index'),			// 导出
	]
	
	render(){
		return (
			<>
				<Page title='物料模板' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this, { type: -1 }) }
				</Page>
			</>
		)
	}
}

export default Index